
//---------------
//群数据

import { friendData } from "./friendData";

//---------------
export class groupData {
    constructor(
        _Id: number = -1,
        _name: string = '',
        _notice: string = '',
        _groupLeaderId: number = null,
        _groupControllerIdArr: number[] = [],
        _groupMemberIdArr: number[] = [],
        _groupAllMemberDataArr: any = {},
        _groupSilenceIdArr: number[] = [],
        _groupRequestInfoArr: any[] = [],
        _isProtectModel: boolean = false,
        _isSilenceAll: boolean = false,
        _isClub: boolean = false,
        _isTop: boolean = false,
        _isDontBother: boolean = false,
        _gameRule: string = '',
        // _invitePer: boolean = true,
        _memberNum: number = 0,
        _unreadMsgNum: number = 0,
        _readedMsgId: number = 0,
        _diedMemberData: any = {},
        _gameNum: number = 1,
        _isShowName: boolean = false,
        _memberExtendedNum: number = 0
    ) {
        this.Id = _Id;
        this.name = _name;
        this.notice = _notice;
        this.groupLeaderId = _groupLeaderId;
        this.groupControllerIdArr = _groupControllerIdArr;
        this.groupMemberIdArr = _groupMemberIdArr;
        this.groupAllMemberDataArr = _groupAllMemberDataArr;
        this.groupSilenceIdArr = _groupSilenceIdArr;
        this.groupRequestInfoArr = _groupRequestInfoArr;
        this.isProtectModel = _isProtectModel;
        this.isSilenceAll = _isSilenceAll;
        this.isClub = _isClub;
        this.group = true;
        this.isTop = _isTop;
        this.isDontBother = _isDontBother;
        this.gameRule = _gameRule;
        // this.invitePer = _invitePer;
        this.memberNum = _memberNum;
        this.unreadMsgNum = _unreadMsgNum;
        this.readedMsgId = _readedMsgId;
        this.diedMemberData = _diedMemberData;
        this.gameNum = _gameNum;
        this.isShowName = _isShowName;
        this.memberExtendedNum = _memberExtendedNum;
    }
    public Id: number;//群ID
    public name: string;//群名
    public url: string;//如果群主更换了头像则使用该图片
    public urls: string[];//默认头像链接(由群主,管理, 成员头像组成)
    public notice: string;//群公告
    public groupLeaderId: number;//群主id
    public groupControllerIdArr: number[];//群管理id
    public groupMemberIdArr: number[];//成员id
    public groupAllMemberDataArr: any;//群成员信息数组(包括群主和管理员)
    public groupSilenceIdArr: number[];//群禁言列表
    public groupRequestInfoArr: any[];//进群申请列表(GroupRequest)
    public isProtectModel: boolean;//是否保护模式(保护模式无法通过群成员添加好友)
    public isSilenceAll: boolean;//群体禁言
    public isClub: boolean;//是否代理群
    public group: boolean;//是群
    public gameRule: string;//玩法
    // public invitePer: boolean;//邀请权限
    public memberNum: number; //成员人数
    public gameNum: number;//俱乐部的游戏数 
    public memberExtendedNum: number;//已扩容数量
    //本地存储字段
    public isTop: boolean;//是否置顶
    public isDontBother: boolean;//是否免打扰
    public unreadMsgNum: number;//未读消息数
    public readedMsgId: number;//已读最新消息
    public diedMemberData: any;//被删除的成员信息
    public isShowName: boolean;//是否在聊天界面展示昵称    


    public static s2cData(data: any) {
        if (!data) return;
        let newGroupData: groupData = new groupData();
        newGroupData.Id = data.gid;
        newGroupData.name = data.name;
        newGroupData.notice = data.note;
        newGroupData.groupLeaderId = data.owner;
        newGroupData.isSilenceAll = data.forbid;
        newGroupData.isProtectModel = data.protect;
        newGroupData.groupSilenceIdArr = data.saymsg;
        newGroupData.groupControllerIdArr = data.admin;
        newGroupData.groupRequestInfoArr = data.request;
        newGroupData.memberNum = data.members.length;
        let allMembers = data.members;
        for (let i in allMembers) {
            let _userData = allMembers[i];
            let _friendData = friendData.s2cData(_userData);
            if (_friendData.Id != newGroupData.groupLeaderId &&
                newGroupData.groupControllerIdArr.indexOf(_friendData.Id) == -1) {
                newGroupData.groupMemberIdArr.push(_friendData.Id);
            }
            newGroupData.groupAllMemberDataArr[_friendData.Id] = _friendData;
        }
        newGroupData.isClub = data.type ? true : false;
        newGroupData.memberExtendedNum = data.member_expansion || 0;
        return newGroupData;
    }
    public static contrastData(key: string, localData: any, serverData: any) {
        key == "isTop" ? (localData == null && (localData = false)) :
            (
                key == "isDontBother" ? (localData == null && (localData = false)) :
                    (
                        key == "unreadMsgNum" ? (localData == null && (localData = 0)) :
                            (
                                key == "readedMsgId" ? (localData == null && (localData = 0)) :
                                    (
                                        key == "diedMemberData" ? (localData == null && (localData = {})) :
                                            (
                                                key == "isShowName" ? (localData == null && (localData = false)) :
                                                    localData = serverData
                                            )
                                    )
                            )
                    )
            );
        return localData;
    }
}
export enum ModifyGroupEnum {
    NAME = 0,       // 群名字更改
    NOTE = 1,       // 群公告更改
    OWNER = 2,      // 群主移交
    FORBID = 3,     // 全体禁言标志更改
    PROTECT = 4,    // 群保护模式标志更改
    SAYMSG_ADD = 5, // 禁言成员添加
    SAYMSG_DEL = 6, // 禁言成员删除
    ADMIN_ADD = 7,  // 管理员添加
    ADMIN_DEL = 8,  // 管理员删除
    REQUEST = 9,    // 群请求变动
    MEMBER_ADD = 10,// 新增成员
    MEMBER_DEL = 11,// 移除成员
}